﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Game.System.EventSystem
{
    public class GameEvent : GameBaseEvent
    {
        //事件的响应委托
        public delegate void ResponseHandle(params object[] args);
        protected ResponseHandle m_Response;

        //事件触发条件委托
        public delegate bool CheckHandle(out object[] args);
        protected CheckHandle m_CheckHandle;

        //接收的参数
        protected object[] m_Args;

        public GameEvent(string eventName)
        {
            name = eventName;
        }

        public override void Update()
        {
            if (!enable)
            {
                return;
            }

            //检查触发条件
            if (m_CheckHandle != null && m_CheckHandle(out m_Args))
            {
                if (m_Response != null)
                {
                    m_Response(m_Args);
                }
            }
        }

        public void AddCheckHandle(CheckHandle check)
        {
            m_CheckHandle += check;
        }

        public void RemoveCheckHandle(CheckHandle check)
        {
            m_CheckHandle -= check;
        }

        public void AddResponse(ResponseHandle response)
        {
            m_Response += response;
        }

        public void RemoveResponse(ResponseHandle response)
        {
            m_Response -= response;
        }
    }
}
